﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Drawing;
using System.Data;
using System.Linq;
using System.Text;
using System.Windows.Forms;

using SharedGenomics.Workbench.Core;
using SharedGenomics.Core;
using SharedGenomics.Workbench.PresentationModel;

namespace SharedGenomics.Workbench.Views.WindowsForms
{
    public partial class CategoryFilterView : View, ICategoryFilterView
    {
        private CheckedComboBox ccbValues;

        public CategoryFilterView()
        {
            InitializeComponent();

            Color previousBackColour = this.btClose.BackColor;
            this.btClose.MouseEnter += new EventHandler((o,e) => { this.btClose.BackColor = Color.LightSkyBlue; });
            this.btClose.MouseLeave += new EventHandler((o, e) => { this.btClose.BackColor = previousBackColour; });

            this.ccbValues = new CheckedComboBox();
            ToolStripControlHost host = new ToolStripControlHost(new MonthCalendar());
            var dropDown = new ToolStripDropDown();
            dropDown.Items.Add(this.ccbValues);
            ToolStripMenuItem mi = new ToolStripMenuItem("Category values");
            mi.DropDown = dropDown;
            this.toolStrip.Items.Add(mi);
        }

        public IEnumerable<ValueDisplayItem<string>> AvailableCategories
        {
            set { this.cmbCategories.Items.AddRange(value.Cast<object>().ToArray()); }
        }

        public IEnumerable<ValueDisplayItem<string>> AvailableValues
        {
            set { this.ccbValues.Items = value.Cast<ValueDisplayItem>(); }
        }

        public string SelectedCategory
        {
            get 
            {
                ValueDisplayItem<string> selectedItem = this.cmbCategories.SelectedItem as ValueDisplayItem<string>;
                return selectedItem == null ? null : selectedItem.TypedValue;
            }
        }

        public IEnumerable<string> SelectedValues
        {
            get { return this.ccbValues.SelectedValues.Cast<string>(); }
        }

        public event EventHandler SelectedCategoryChanged;
        public event EventHandler RemoveClicked;
        public event EventHandler AddNewClicked;

        private void btClose_Click(object sender, EventArgs e)
        {
            this.RemoveClicked.Raise(this);
        }

        private void cmbCategories_SelectedIndexChanged(object sender, EventArgs e)
        {
            this.SelectedCategoryChanged.Raise(this);
        }

        private void tsbAddNew_Click(object sender, EventArgs e)
        {
            this.AddNewClicked.Raise(this);
        }
    }
}
